/*
 * Copyright(C) 2012 Luvina Software Company
 *
 * MstJapanDaoImpl.java, Jun 5, 2012 HaiPD
 */
package net.luvina.manageuser.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.transform.Transformers;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Repository;

import net.luvina.manageuser.dao.MstJapanDao;
import net.luvina.manageuser.hibernate.MstJapan;

/**
 * MstJapanDaoImpl implements MstJapanDao
 *
 * @author HaiPD
 *
 */
@Repository("japanDao")
public class MstJapanDaoImpl extends GenericDaoImpl<MstJapan, Integer>
		implements MstJapanDao {

	public MstJapanDaoImpl() {
		super(MstJapan.class);
		// TODO Auto-generated constructor stub
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see net.luvina.manageuser.dao.MstJapanDao#getListJapan()
	 */
	@SuppressWarnings("unchecked")
	public List<MstJapan> getListJapan() {
		HibernateCallback callback = new HibernateCallback() {

			@Override
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				StringBuilder sqlCommand = new StringBuilder();
				sqlCommand.append("SELECT ");
				sqlCommand.append("code_level as codeLevel, ");
				sqlCommand.append("name_level as nameLevel ");
				sqlCommand.append("FROM mst_japan as g ");

				Query query = session.createSQLQuery(sqlCommand.toString())
						.addScalar("codeLevel", Hibernate.STRING).addScalar(
								"nameLevel", Hibernate.STRING)
						.setResultTransformer(
								Transformers.aliasToBean(MstJapan.class));
				return (List<MstJapan>) query.list();
			}

		};
		return (List<MstJapan>) getHibernateTemplate().execute(callback);
	}

}
